<!-- <h4 class="title-bg">结算信息</h4> -->
<div id="b2c-checkout-coupon" style="border:1px solid #ddd; padding:10px; border-bottom:none"> <a href="javascript:;" class="siteparttitle-blue coupon-icon" onclick="show_add_coupon(this,'id-add-coupon')" ><{t}>使用优惠券<{/t}></a>
  <div style="clear:both;  margin:5px 0; ">
    <table id="id-add-coupon" cellpadding="0" cellspacing="0"border="0" width="100%"class="tableform" style="<{if !$aCart.object.coupon}>display:none; margin:5px 0;<{/if}>" >
      <tr>
        <td width="20%" align="right" style="vertical-align:middle; padding:10px"><{t}>优惠券名称：<{/t}></td>
        <td style="padding:10px; vertical-align:middle">
            <select id="b2c-checkout-member-coupon">
                <option value=""><{t}>-- 选择优惠券 --<{/t}></option>
                <{if $coupon_lists}>
                <{foreach from=$coupon_lists item=list_coupon}>
                <option value="<{$list_coupon.memc_code}>"><{$list_coupon.coupons_info.cpns_name}></option>
                <{/foreach}>
                <{/if}>
            </select>
        </td>
        <td width="80%" style="padding:10px"><div id='cart-coupon-add' style="height:26px; line-height:26px"> <{assign var=___df value=$___b2c='请输入优惠券号码'|t:'b2c'}>
            <{input type="text" name="coupon" id='cart-coupon-inputtext' size="25" value=$___b2c="请输入优惠券号码"|t:'b2c' }>
            <button type="button" class="btn " style="*margin:-8px 0 0 8px" id='cart-coupon-submitBtn' > <span><span><{t}> 使用<{/t}></span></span> </button>
            <script>
              $('cart-coupon-submitBtn').addEvent('click',function(e){
                  e.stop();
                  new Element('form',{method:'post',action:'<{link app=b2c ctl="site_cart" act="addToCart" arg0="coupon"}>'}).adopt($('cart-coupon-add').clone()).inject(document.body).submit();
              });
              $('cart-coupon-inputtext').addEvent('keypress',function(e){
                if(e.code==13){
                    e.stop();
                    $('cart-coupon-submitBtn').fireEvent('click',{stop:$empty});

                }
              });
             </script>
          </div></td>
      </tr>
      <!--<tr>
        <td></td>
        <td><{if $login!='nologin'}><a href="<{link app=b2c ctl=site_member act=coupon}>" target="_blank" ><{t}>查看已有的优惠券<{/t}></a><{/if}></td>
      </tr>-->
      <tr>
        <td colspan="3"><{if $aCart.object.coupon}>
          <div id="cart-coupon-list">
            <table width="100%" cellpadding="3" cellspacing="0" id="coupon-list-table" class="gridlist liststyle cart-list" >
              <col style="width:20%">
              <col style="width:60%">
              <col style="width:10%" >
              <col style="width:10%" >
              </col>

              <thead>
                <tr>
                  <th><{t}>优惠券号码<{/t}></th>
                  <th><{t}>优惠券<{/t}></th>
                  <!--<th><{t}>描述<{/t}></th>-->
                  <th><{t}>是否适用<{/t}></th>

                  <th><{t}>删除<{/t}></th>
                  </tr>
              </thead>
              <tbody >
              <{foreach from=$aCart.object.coupon item=coupon}>
              <tr urlremove="<{link app=b2c ctl='site_cart' act='removeCartCoupon' arg0='coupon'}>">
                <td class="textcenter">
                  <{$coupon.coupon}>
                </td>
                <td class="textcenter">
                  <input type="hidden" value="<{$coupon.obj_ident}>" />

                  <{$coupon.name}> </td>
                <!--<td><{$coupon.description}></td>-->
                <td class="textcenter"><{if $coupon.used}><font color='green'><{t}>是<{/t}></font><{else}><font color='red'><{t}>否<{/t}></font><{/if}></td>

                <td class="textcenter"><span><{img src='icons/icon_delete.gif' app=b2c alt=$___b2c='删除'|t:'b2c' style='cursor:pointer' class="delItem"}></span></td>
                </tr>
              <{/foreach}>
            </table>
          </div>
          <{/if}> </td>
      </tr>
    </table>
  </div>
</div>

<script>
function show_add_coupon(el,id) {
    if( !$(id) ) return ;
    var _o = $(id);
    if( _o.getStyle('display')=='none' ) {
        _o.setStyle('display', 'inline');
        $(el).removeClass('coupon-icon');
        $(el).addClass('coupon-icon-');
    } else {
        _o.setStyle('display', 'none');
        $(el).removeClass('coupon-icon-');
        $(el).addClass('coupon-icon');
    }
}

Cart=new Object();

Object.append(Cart,{
    init:function(){
        $$('input[name^=coupon]').addEvents({
            'focus':function(el){
                if ($(el.target).value == '<{$___df}>'){
                    $(el.target).value = '';
                }
            },
            'blur':function(el){
                if ($(el.target).value == ''){
                    $(el.target).value = '<{$___df}>';
                }
            }
        });

        $('b2c-checkout-coupon').addEvent('click',function(e){
            var target=$(e.target);
            if(target.hasClass('delItem')){
                Cart.removeItem(target)
            }
        });

        $('b2c-checkout-member-coupon').addEvent('change',function(e){
            $('cart-coupon-inputtext').value = $(e.target).get('value');
        });
    },
    removeItem:function(handle){
     Ex_Dialog.confirm('<{t}>确认删除？<{/t}>', function(e){
       if(!e) return;
       var item = $(handle).getParent('tr');
       var remoteURL = item.get('urlremove');
       item.getElements('input').set('disabled',true);
       var _item_data = item.getElement('input[type="hidden"]');
       Cart.updateTotal(item, remoteURL, _item_data.value);
     });
    },
    updateTotal:function(item, remoteURL, indent){
    new Request({
        url:remoteURL,
        method:'post',
        data:'cpn_ident='+indent,
        onRequest:function(){
            if(!Browser.ie6){
                 item.getFirst().set({'html':'<{t}>正在删除...<{/t}>'});
                 item.setStyles({'background':'#FBE3E4','opacity':1})
            }
        },
        onComplete:function(res){
            var _response = JSON.decode(res);
            if (_response.success){
                var _tr = item.getParent('table').getElement('tbody').getElements('tr');
                if (_tr.length==1)
                    item.getParent('table').destroy();
                else
                    item.destroy();
                Order.updateTotal();
            }else{
                MessageBox.error(_response.error);
            }
        }
    }).send();
    }
});

(function(){
    Cart.init();
})();
</script>